/*
 * add for write files to board
*/


#include <common.h>
#include <command.h>
#include <fs.h>

static int do_ewrite(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
    int rcode = 0;
    loff_t size;

    if(argc < 2)
    {
        printf("Your input cmd number is less 2!!!");
        return CMD_RET_USAGE;
    }

    printf("do_ewrite in\n");

    run_command("usb start", 0);

    if(strcmp(argv[1], "uboot") == 0)
    {

        if(fs_set_blk_dev("usb", "0", FS_TYPE_FAT))
            return 1;

        if(fs_size("u-boot.bin", &size) < 0)
            return 1;
         
        printf("size:lld%\n", size);

        run_command("fatload usb 0 0x30000000 u-boot.bin",0);

        run_command("protect off all",0);
        run_command("erase 0x0 0x0008ffff",0);
        run_command("cp.b 0x30000000 0x0 0x90000",0);

        run_command("protect on all",0);

    }
    

    run_command("usb stop", 0);


    
    return 0;
}

U_BOOT_CMD(ewrite, 2, 0, do_ewrite,
	"write files to board",
	"write files like uboot, image and so on")

